import QtQuick 2.0

import com.yihu.xchat.enum 1.0
import com.yihu.xchat.model 1.0

Rectangle {
    anchors.fill: parent

    // 默认背景
    color: "#EEEEEE"
    Image {
        anchors.centerIn: parent

        source: "qrc:/images/chatting_view_background.png"
    }

    // 列表区域
    Rectangle {
        anchors.top: parent.top
        anchors.left: parent.left

        width: 200
        height: parent.height

        ListView {
            id: groupsList

            anchors.fill: parent

            clip: true

            // 委托
            delegate: groupDelegate

            // 模型
            model: GroupsSingleton

            // 高亮
            highlight: Rectangle {
                color: "lightgray"
                focus: true
            }
        }

        Component {
            id: groupDelegate

            Rectangle {
                height: 40
                width: parent.width
                color: "transparent"

                Image {
                    id: photo
                    anchors.verticalCenter: parent.verticalCenter

                    x: 5
                    width: 32
                    height: 32
                    source: "qrc:/images/avatar_default_group.png"
                }

                Text {
                    id: groupName
                    anchors.verticalCenter: parent.verticalCenter

                    x: photo.width + photo.x * 2
                    font.bold: false
                    font.pixelSize: 15
                    text: name
                }

                Image {
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right: parent.right
                    anchors.rightMargin: 5

                    width: 16
                    height: 16
                    visible: mute
                    source: "qrc:/images/group_mute.png"
                }

                MouseArea {
                    anchors.fill: parent

                    onClicked: {
                        groupsList.currentIndex = index;
                    }

                    onDoubleClicked: {
                        // 双击打开新的会话
                        SessionsSingleton.createSession(id, X.Group);
                        rootView.switchTopLevelView(rootView.topLevelViews.sessionsView);
                    }
                }
            }
        }
    }
}
